using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using WozLib.WozObjects;

namespace WozLib.WozCommands
{
  /// <summary>
  /// This derived class of WozServerCommand can store a single ServerObjectID
  /// as a parameter to the command.
  /// </summary>
  public class WozObjectWozCommand : WozCommand
  {
    
    /// <summary>
    /// Stores the ServerID of the target of the IServerObject of the derived class.
    /// </summary>
    [XmlAttribute("TargetServerID")]
    public long TargetServerID
    {
      get { return _TargetServerID; }
      set { _TargetServerID = value; }
    } private long _TargetServerID;

    /// <summary>
    /// Returns the IServerObject that is the target of this command. Returns null if none exists.
    /// </summary>
    [XmlIgnore]
    public IServerObject TargetIServerObject
    {
      get
      {
        return ServerObjectRegistry.GetObject(TargetServerID);
      }
      set
      {
        TargetServerID = value.ServerID;
      }
    }
	

    /// <summary>
    /// Default Constructor: Should primarily used for XML DeSerialization
    /// </summary>
    public WozObjectWozCommand()
    {
    }

    /// <summary>
    /// Creates a WozServerObjectServerCommand with a targetServerID.
    /// </summary>
    /// <param name="targetServerID">the ServerID of the target IServerObject</param>
    public WozObjectWozCommand(long targetServerID)
    {
      TargetServerID = targetServerID;
    }

    /// <summary>
    /// Creates a WozServerObjectServerCommand with a targetServerID of the targetIServerObject.
    /// </summary>
    /// <param name="targetIServerObject">IServerObject to get save a ServerID from as the target IServerObject</param>
    public WozObjectWozCommand(IServerObject targetIServerObject)
    {
      TargetServerID = targetIServerObject.ServerID;
    }
  }
}
